home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Programming Contest / MacHack Contest.sit / MacHack Contest / Problems Folder / Problem 07 - Graph / Solution.p / Solution.p
Encoding:
Text File  |  1998-06-18  |  2.0 KB  |  59 lines  |  [TEXT/CWIE]

  1. (*
  2. Problem 07 - Graph
  3.  
  4. procedure GraphInit( var graph: Handle; verrticies: UInt32 );
  5. procedure GraphAddDirectedEdge( graph: Handle; vertex1, vertex2: UInt32 );
  6. procedure GraphFindRoute( graph: Handle; vertex1, vertex2: UInt32; var
  7. verticies: Handle );
  8.  
  9. Your task is to write a set of routines to create and traverse a directed
  10. graph.
  11.  
  12. GraphInit creates a new, empty directed graph ready to accept directed edges
  13. with verrticies verticies.  
  14.  
  15. GraphAddDirectedEdge adds a directed edge from vertex1 to vertex2
  16.  
  17. GraphFindRoute find a route from vertex1 to vertex2.  If such a route exists,
  18. then verticies is returns as a real Mac handle to an array of UInt32s, the
  19. first is vertex1, the last is vertex2.  Each successive vertex must have
  20. previously had an edge added with GraphAddDirectedEdge.  If no route exists,
  21. return nil for verticies.  No vertex should appear more than once in the
  22. verticies handle, except for the case where vertex1 is the same as vertex2, in
  23. which case you must find a circular route from vertex1 back to itself and so
  24. vertex1 will appear exactly twice, once at the start and once at the end of the
  25. verticies handle.
  26.  
  27. All the graph information must be stored in the real Mac memory manager handle
  28. - it will be disposed with DisposeHandle and that must release all memory, so
  29. dont store any extra information outside the handle.  Also, you must be able to
  30. deal with having multiple graphs instantiated simultaneously.
  31. *)
  32.  
  33. unit Solution;
  34.  
  35. interface
  36.  
  37. // Do not modify the interface
  38.  
  39.     uses
  40.         Types, Files;
  41.         
  42.     type
  43.         UInt32Array = array[0..0] of UInt32;
  44.         UInt32ArrayPtr = ^UInt32Array;
  45.         UInt32ArrayHandle = ^UInt32ArrayPtr;
  46.  
  47.     procedure GraphInit( var graph: Handle; verticies: UInt32 );
  48.     procedure GraphAddDirectedEdge( graph: Handle; vertex1, vertex2: UInt32 );
  49.     procedure GraphFindRoute( graph: Handle; vertex1, vertex2: UInt32; var verticies: UInt32ArrayHandle );
  50.  
  51.  
  52. implementation
  53.  
  54. // Fill in your solution and then submit this folder
  55.  
  56. // Team Name: FILL IN YOUR TEAM NAME!
  57.  
  58. end.
  59.